package com.app.teaware.statis;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.app.teaware.R;
import com.app.teaware.basis.BasisFragment;
import com.app.teaware.basis.Constants;
import com.app.teaware.bean.StatisChartInfoBean;
import com.app.teaware.bean.StatisFireRiskBean;
import com.github.mikephil.charting.charts.LineChart;

import butterknife.BindView;
import butterknife.OnClick;
import my.http.MyHttpListener;
import my.http.MyHttpUtils;
import my.http.MyParams;

/**
 *统计分析-防火监督数据分析
 */
public class FireRiskStatisFragment extends BasisFragment{


    @BindView(R.id.chart_line)
    LineChart chart_line;

    String type_current = "month";

    @BindView(R.id.text_month)
    TextView text_month;
    @BindView(R.id.text_season)
    TextView text_season;
    @BindView(R.id.text_year)
    TextView text_year;
    StatisChartInfoBean mStatisChartInfoBean;

    public static FireRiskStatisFragment newInstance() {
        FireRiskStatisFragment fragment = new FireRiskStatisFragment();
        return fragment;
    }

    @Override
    public void initViews() {
//        super.initViews();
        setContentView(R.layout.statis_firerisk_fragment);


    }

    @Override
    public void initData(Bundle savedInstanceState) {
        type_current =  "month";
        text_month.setSelected(true);
        getList();
    }



    private void getList() {

        MyParams params = new MyParams();
        showProgress();
        params.put("type", type_current);

        MyHttpUtils.post(Constants.URL_STATIS_FIRRISK, params, new MyHttpListener() {
                    @Override
                    public void onSuccess(int httpWhat, Object result) {
                        StatisFireRiskBean statisFireRiskBean = (StatisFireRiskBean) result;
                        mStatisChartInfoBean = statisFireRiskBean.getChartInfoBean();
                        mStatisChartInfoBean.setChartLine(mContext,chart_line);
                    }

                    @Override
                    public void onFailure(int httpWhat, Object result) {
                        super.onFailure(httpWhat, result);
                    }

                    @Override
                    public void onFinish(int httpWhat) {
                        dismissProgress();
                    }
                },
                0, StatisFireRiskBean.class);

    }



    @OnClick({R.id.text_month,R.id.text_season,R.id.text_year})
    void onTimeTabClick(View view){
        String tag = (String) view.getTag();
        if(tag.equals(type_current))return;
        text_month.setSelected(false);
        text_season.setSelected(false);
        text_year.setSelected(false);
        view.setSelected(true);
        type_current = tag;
                getList();
    }

}
